package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Demo3 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        /*

        //1.加载驱动(每种数据库驱动的类名和包名都是固定的)
        Class.forName("com.mysql.cj.jdbc.Driver");

        //2.通过驱动管理器建立链接 DriverManaher.getConnection()
        Connection connection = DriverManager.getConnection(//  本机地址：端口好/数据库
                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "root");
        System.out.println("与数据库建立链接！");

        */



        Connection connection = DBUtil.getConnection();
        //3.通过连接对象创建执行语句对象Statement
        Statement statement = connection.createStatement();

        String  sql  = "UPDATE user\n" +
                "SET password = '666666',nickname = '老三',age = 33\n" +
                "WHERE id = 1";

        int num = statement.executeUpdate(sql);
        if(num > 0){
            System.out.println("修改成功");
        } else {
            System.out.println("修改失败");
        }
        connection.close();

    }
}
